class Solution(object):
    def rearrangeArray(self, nums):
        nums.sort()
        ans = []
        n = len(nums)
        for i in range(n // 2):
            ans.append(nums[i])
            ans.append(nums[n - 1 - i])
        if n % 2:
            ans.append(nums[n // 2])
        return ans